package com.huiminpay.merchant.web;

import com.huiminpay.merchant.api.AppService;
import com.huiminpay.merchant.dto.AppDTO;
import com.huiminpay.merchant.util.SecurityUtil;
import com.huiminpay.transaction.api.PayChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName AppController
 * @Description:
 * @Author: longlong
 * @CreateDate: 2023/11/30 15:34
 * @Version: 1.0
 */
@Slf4j
@Api(tags = "商户平台-应用管理")
@RestController
public class AppController {

    @Reference
    AppService appService;

    @Reference
    PayChannelService payChannelService;

    @ApiOperation("商户应用创建")
    @PostMapping("/my/apps")
    public AppDTO saveMerchant(@RequestBody AppDTO dto) {
        Long merchantId = SecurityUtil.getMerchantId();
        return appService.createApp(merchantId, dto);
    }

    /**
     * 根据appId 查询应用详情
     *
     * @param appId
     * @return com.huiminpay.merchant.api.dto.AppDTO
     * @author qawine
     * @date 2021/3/24 20:32
     */
    @ApiOperation("根据appid获取应用的详细信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "appId", value = "商户应用id", required = true, dataType = "String", paramType = "path")})
    @GetMapping(value = "/my/apps/{appId}")
    public AppDTO getApp(@PathVariable String appId) {
        return appService.getAppById(appId);
    }

    @ApiOperation("查询应用是否绑定了某个服务类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appId", value = "应用appId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "platformChannel", value = "服务类型", required = true, dataType = "String", paramType = "query")
    })
    @GetMapping("/my/merchants/apps/platformchannels")
    public int queryAppBindPlatformChannel(@RequestParam String appId, @RequestParam String platformChannel) {
        return payChannelService.queryAppBindPlatformChannel(appId, platformChannel);
    }

}
